<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <title>Picker - isOpen</title>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
    />
    <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
    <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
    <script src="../../../../../scripts/testing/scripts.js"></script>
    <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
  </head>

  <body>
    <ion-app>
      <ion-header>
        <ion-toolbar>
          <ion-title>Picker - isOpen</ion-title>
        </ion-toolbar>
      </ion-header>

      <ion-content class="ion-padding">
        <button id="default" onclick="openPicker()">Open Picker</button>
        <button id="timeout" onclick="openPicker(500)">Open Picker, Close After 500ms</button>

        <ion-picker-legacy></ion-picker-legacy>
      </ion-content>
    </ion-app>

    <script>
      const picker = document.querySelector('ion-picker-legacy');
      picker.buttons = [{ text: 'Ok' }, { text: 'Cancel', role: 'cancel' }];
      picker.columns = [
        {
          name: 'Colors',
          options: [
            {
              text: 'Red',
              value: 'red',
            },
            {
              text: 'Blue',
              value: 'blue',
            },
            {
              text: 'Green',
              value: 'green',
            },
          ],
        },
      ];

      const openPicker = (timeout) => {
        picker.isOpen = true;

        if (timeout) {
          setTimeout(() => {
            picker.isOpen = false;
          }, timeout);
        }
      };

      picker.addEventListener('ionPickerDidDismiss', () => {
        picker.isOpen = false;
      });
    </script>
  </body>
</html>
